kosovawikiaorg-20200215-history
Help:Table
The sample text ("header 1" or "row 1, cell 1") is to be replaced with actual data. |} __TOC__ Pipe syntax tutorial Although HTML table syntax also works, special wikicode can be used as a shortcut to create a table. The pipe (vertical bar) codes function exactly the same as HTML table markup, so a knowledge of HTML table code will help in understanding pipe code. The shortcuts are as follows: * The entire table is encased with curly brackets and a vertical bar character (a pipe). So use ' ' to end it. Each one needs to be on its own line: ' ' * An optional table caption is included with a line starting with a vertical bar and plus sign "|+" and the caption after it: * To start a new table row, type a vertical bar and a hyphen on its own line: "|-'". The codes for the cells in that row will start on the next line. * Type the codes for each ''table cell in the next row, starting with a bar: * Cells can be separated with either a new line and new bar, or by a double bar "||'" on the same line. Both produce the same output: * If you use single bars, then what might appear to be the first cell is in fact a format modifier applied to the cell, and the rest of your "cells" will be merged into one: which is probably not what you want: However, the format modifier is useful: Just remember: no more than 2 single pipes on a line! * a row of '''column headings' is identified by using "!" instead of "|", and using "!!" instead of "||". Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered. * the first cell of a row is identified as a row heading by starting the line with "!" instead of "|", and starting subsequent data cells on a new line. * Optional parameters can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table: The final table would display like this: The table parameters and cell parameters are the same as in HTML, see http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE and Table (HTML). However, the thead, tbody, tfoot, colgroup, and col elements are currently not . A table can be useful even if none of the cells have content. For example, the background colors of cells can be changed with cell parameters, making the table into a diagram, like meta:Template talk:Square 8x8 pentomino example. An "image" in the form of a table is much more convenient to edit than an uploaded image. Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent. For empty cells, use the non-breaking space as content to ensure that the cells are displayed. To show a visible pipe in a cell, use | or |. With colspan and rowspan cells can span several columns or rows, see the example below. However, this has the disadvantage that sorting does not work properly anymore. Examples Simple example Both of these generate the same output. Choose a style based on the number of cells in each row and the total text inside each cell. The wiki markup code: What it looks like in your browser: Multiplication table The wiki markup code: What it looks like in your browser (see: ): Color; scope of parameters Two ways of specifying color of text and background for a single cell are as follows. The first form is preferred: The wiki markup code: What it looks like in your browser: Like other parameters, colors can also be specified for a whole row or the whole table; parameters for a row override the value for the table, and those for a cell override those for a row. (Note that there is no easy way to specify a color for a whole column—each cell in the column must be individually specified. Tools can make it easier.): The wiki markup code: What it looks like in your browser: To make the table blend in with the background, use style="background:none" or style="background:transparent". (Warning: style="background:inherit", does not work with some browsers, including IE6!) To force a cell to match one of the default colors of the , use style="background:#f2f2f2" for the darker header, and style="background:#f9f9f9" for the lighter body. See : style, background, list of colors, web colors Width, height The width and height of the whole table can be specified, as well as the height of a row. To specify the width of a column one can specify the width of an arbitrary cell in it. If the width is not specified for all columns, and/or the height is not specified for all rows, then there is some ambiguity, and the result depends on the browser. The wiki markup code: What it looks like in your browser: Note that style="inline CSS" has no effect with some browsers. If compatibility is important, equivalent older constructs like width="75%" should work on more browsers. Setting your column widths If you wish to force column widths to your own requirements, rather than accepting the width of the widest text element in a column's cells, then follow this example. Note that wrap-around of text is forced. The wiki markup code: To set column widths in a table without headers, specify the width in the first cell for each column, like this: One application of setting the widths is aligning columns of consecutive tables: Setting borders Table borders default to a complex shaded double-line (the default in HTML); however, those borders can be set to a thin solid line by using a style-parameter (style="border:1px solid darkgray"), as in the following (Note: if you intend to use the 'cellpadding' or 'cellspacing' options along with a border, you MUST use this format): Note the bottom-row texts are centered by "align=center" while star-images were not centered. As long as the "Image:" specs omit the parameter "thumb|" they will not show the caption lines in the table (only during mouse-over). The border color "darkgray" matches typical tables or infoboxes in articles; however, it could be any color name (such as style="border:1px solid darkgreen;") or use a hex-color (such as: #DDCCBB). A column format-specifier (enclosed in "|...|") can have a style-parameter to set borders on each cell, as follows: Note only the image cells, here, have individual borders, not the text. The lower hex-colors (such as: #616161) are closer to black. Typically, all borders in a table would be one specific color. Caveats Never use class="wikitable" without also using border="1", or you will produce accessibility problems. Vertical alignment By default data in tables is vertically centrally aligned, which results in odd-looking layouts like this: To fix this, apply the valign="top" attribute to the rows (unfortunately it seems to be necessary to apply this individually to every single row). For example: Positioning You can position the table itself, the contents of a row, and the contents of a cell, but not with a single parameter for all the contents of the table. See m:Template talk:Table demo. Prior to April 2009, using "float" to position a table was discouraged; however, it no longer always breaks page rendering at large font sizes. See a floated image, below, under "Floating images in the center". Mélange Here's a more advanced example, showing some more options available for making up tables. Note however that with colspan and rowspan sorting does not work properly anymore. You can play with these settings in your own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because you can add colored backgrounds, for example, doesn't mean it's always a good idea. Try to keep the markup in your tables relatively simple -- remember, other people are going to be editing the article too! This example should give you an idea of what is possible, though. The wiki markup code: |} What it looks like in your browser: |} Floating table The wiki markup coding: This paragraph is before the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod... Note the floating-table to the right. This paragraph is after the table. The text in column 2 will span both rows due to format specifier "rowspan=2" so there is no coding for "Col 2" in the 2nd row, just: Col 1 & Col 3. What it looks like in your browser: This paragraph is before the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod... Note the floating-table to the right. This paragraph is after the table. The text in column 2 will span both rows due to format specifier "rowspan=2" so there is no coding for "Col 2" in the 2nd row, just: Col 1 & Col 3. Floating images in the center A table can be used to wrap an image, so that the table can float towards the center of the page (such as using: style="float: right;"). However, the table margins, border and font-size must be precisely set to match a typical image display. The Image-spec parameter "thumb|" (although auto-thumbnailing to user-preference width) forces a wide left-margin that squeezes the nearby text, so the parameter "center|" can be added to suppress the left-margin padding. However, "center" sometimes shoves the caption to a 2nd line (under a centered box "[]"), so "thumb|" could be omitted and just hard-code the image size, adding a gray (#BBB) border. Using precise parameters to match other images, a floating-image table can be coded as follows: The text inside the floating-table is sized by style="font-size:86%". That floating-image table floats a typical image-box, but allows adjusting the left-hand margin of the image (see temple-example floating below). The caption-text can be omitted, or remove the parameter "thumb|" so the caption is hidden until "mouse-over display". Unfortunately the parameter "thumb|" (used for displaying the caption) also controls the auto-thumbnailing to re-size images by user-preferences size. In April 2009, it was not possible to have auto-thumbnail sizing while also concealing the caption: parameter "thumb|" triggers both actions and forces the caption to display. An image set with parameter "left|" will gain a wide right-side margin (opposite margin of parameter "right|"), so floating toward the left would require an image set as "center|" inside a table with style="float:left; margin:0.46em 0.2em". Recall that, outside an image-table, the parameter "right|" causes an image to align (either) above or below an infobox, but would not float alongside the infobox. Note the order of precedence: first come infoboxes or images using "right|", then come the floating-tables, and lastly, any text will wrap that can still fit. If the first text-word is too long, no text will fit to complete the left-hand side, so beware creating a "ragged left margin" when not enough space remains for text to fit alongside floating-tables. If multiple single image-tables are stacked, they will float to align across the page, depending on page-width. The text will be squeezed to allow as many floating-tables as can fit, as auto-aligned, then wrap whatever text (can still fit) at the left-hand side. That auto-aligning feature can be used to create a "floating-gallery" of images: a set of 20 floating-tables will wrap (backward, right-to-left) as if each table were a word of text to wrap across and down the page. To wrap in the typical direction (wrapping left-to-right) define all those floating-tables, instead, as left-side tables using the top parameter style="float:left; margin:0.46em 0.2em". Multiple floating-images empower more flexible typesetting of images around the text. Nested tables Five different (blue) tables are shown nested inside the cells of a table. Automatically the two tables |A| and |B|B| are vertically aligned instead of the usual side by side of text characters in a cell. "float" is used to fix each of tables |C| and |D| to their own position within one cell of the table. This may be used for charts and schemes. Nested tables must start on a new line. Wiki markup ' | style="vertical-align:bottom;"| the original table again | style="width:100px;" | ' ' ' ' | style="width:50px;" | ' ' ' ' |} '''What it looks like in your browser' | style="vertical-align:bottom;"| the original table again | style="width:100px;" | | style="width:50px;" | |} Combined use of COLSPAN and ROWSPAN Wiki markup What it looks like in your browser Note that using rowspan="2" for cell G''' combined with rowspan="3" for cell '''F to get another row below G''' and '''F won't work, because all (implicit) cells would be empty. Likewise complete columns are not displayed if all their cells are empty. Borders between non-empty and empty cells might be also not displayed (depending on the browser), use to fill an empty cell with dummy content. Centering tables Centered tables can be achieved, but they will not "float"; that is to say, no text will appear to either side. The trick is What it looks like in your browser Setting parameters At the start of a cell, add your parameter followed by a single pipe. For example width="300"| will set that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one, as follows: What it looks like in your browser: Tiny tables within a text line For years in HTML, a table has always forced an implicit line-wrap (or line-break), so to keep a table within a line, the work-around is to put all text into a table, then embed a table-within-a-table, using the outer table to force the whole line to stay together. Consider the following examples: : Wikicode (showing table forces line-break): :: * This is a test table here HELLO WORLD followed by this text afterward. :Result: ::* This is a test table here HELLO WORLD followed by this text afterward. : Wikicode (table-within-table): :: * This is a test table here HELLO WORLD followed by this text afterward. This line is more text after the outer table. :Result: ::* This is a test table here HELLO WORLD followed by this text afterward. This line is more text after the outer table. Use style="font-size:60%" to shrink the text within the box. However, the small text could be replaced with small images (aligned inside the inner table). The outer table is for one line only, so to make a 2nd line appear even, the exact length of line 1 must be pre-determined, to match the length of other lines. Decimal point alignment A method to get columns of numbers aligned at the decimal point is as follows: What it looks like in your browser: If the column of numbers appears in a table with cell padding or cell spacing, you can still align the decimal points without an unsightly gap in the middle. Embed a table in each number's cell and specify its column widths. Make the embedded tables' column widths the same for each cell in the column. (If decimal points are still misaligned using this method, the main table's column may be too narrow. Add a parameter to increase the column's width.) The wiki markup code: |- | |- | |} What it looks like in your browser: |- | |- | |} In simple cases you can dispense with the table feature and simply start the lines with a space, and put spaces to position the numbers: 432.1 43.21 4.321 Style classes :See also . In the first line of table code, after the " becomes this: simply by replacing inline CSS for the table by class="wikitable". This is because the wikitable class in MediaWiki:Common.css contains a number of table.wikitable CSS style rules. These are all applied at once when you mark a table with the class. You can then add additional style rules if desired. These override the class's rules, allowing you to use the class style as a base and build up on it: Wiki markup What it looks like in your browser Notice that the table retains the gray background of the wikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the local style statement; all of the text in the table has been made italic and 120% normal size, and the wikitable border has been replaced by the red dashed border. Of course this works only for browsers supporting inline CSS, if it's important use XHTML markup like instead of "font-size:120%", or Wiki markup like text instead of "font-style:italic". Collapsible tables Classes can also be used to collapse tables, so they are hidden by default. Use the style 'collapsible' to enable collapsing behaviour. By default, a collapsible table will begin expanded. To change this, include the additional class 'collapsed' or 'autocollapse' (i.e. only collapse if 3 other collapsible tables are present). You must include a header row, where the 'hide' option will be displayed. Example: Gives: Sorting Tables can be made sortable by adding class="sortable"; for details see ' '. Since this can be very useful, it is wise to keep the possibilities and limitations of this feature in mind when designing a table. For example: *Do not divide a table into sections by subheaders spanning several rows. Instead, an extra column can be made showing the content of these headers on each row, in a short form. *Do not have elements spanning several columns; instead, again, repeat the content on each row, in a short form. *In a column of numbers, do not put text such as "ca." in front of a number-it will sort like zero. Do not put text after the number, and do not put a range of numbers (it does not affect the sorting position for numeric sorting mode, and in the case of a range, the first number determines the position, but if, possibly after sorting this or another column, the element is at the top, it will induce alphabetic sorting mode). Instead, put these texts in a separate column. Alternatively, for the greatest flexibility, alphabetic sorting mode with hidden sortkeys can be used. A long form of abbreviated content can be put as legend outside the table. Wiki markup What it looks like in your browser Row template Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, has much in common, e.g.: *the basic code for a table row *code for color, alignment, and sorting mode *fixed texts such as units *special formats for sorting In that case it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages: *easily changing the order of columns, or removing a column *easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls) *computing fields from other fields, e.g. population density from population and area *duplicating content and providing span tags with "display:none" for the purpose of having one format for and another for display *easy specification of a format for a whole column, such as color and alignment Example: Using gives: Conditional table row For a conditional row in a table, we can have: Which gives the following table: (note how the second row is missing) Other table syntax Other types of table syntax that MediaWiki supports: #XHTML #HTML & wiki- syntax (Do not use) All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest. Also, HTML & wiki- syntax (i.e., unclosed and tags) will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices. See also Table (HTML), HTML element#Tables. Note however that the thead, tbody, tfoot, colgroup, and col elements are currently not . Comparison of table syntax |- ! Caption | caption | |+ caption |- ! Row | | |- |- ! Data cell | cell1cell2 cell3 | | cell1 || cell2 | cell3 |- ! Header cell | heading | ! heading |- ! rowspan="2" | Sample table | colspan="2" | 1 2 3 4 |- | 1 2 3 4 | |- style="vertical-align:top;" ! Pros | * Can preview or debug with any XHTML editor * Can be indented for easier reading * Well-known * Insensitive to newlines * No characters like "|" which can collide with template and parser function syntax | * Easy to write * Easy to read * Takes little space * Can be learned quickly |- style="vertical-align:top;" ! Cons | * Tedious * Takes a lot of space * Difficult to read quickly * Accidentally putting "tr" for "td" can cause confusion for hours. * Indented code might not match nesting. * In rare cases, newlines can break cells, causing severe confusion since newlines usually are ok. | * Unfamiliar syntax * Rigid structure * Cannot be indented * Text (as in HTML tags) may be easier for some people to read than series of pipes, plus signs, dashes, etc. * Requires using Template:! to pass a "|" in a parameter. * Sensitive to newlines; see . |- ! !! XHTML !! Wiki-pipe |} See also Template talk:For#Tables. Pipe syntax in terms of the HTML produced The pipe syntax, developed by Magnus Manske, substitutes pipes (|) for HTML. There is an on-line script which converts html tables to pipe syntax tables. The pipes must start at the beginning of a new line, except when separating parameters from content or when using || to separate cells on a single line. The parameters are optional. Tables A table is defined by which generates " Insert other text here ". Rows For each table, an HTML tag will be generated for the first row. To start a new row, use: |- which generates another "". Parameters can be added like this: |- params which generates "". Note: * tags will be automatically opened at the first equivalent * tags will be automatically closed at and equivalents Cells Cells are generated either like this: |cell1 |cell2 |cell3 or like this: |cell1||cell2||cell3 which both generate "cell1cell2cell3". The "||" equals "newline" + "|". Parameters in cells can be used like this: |''params''|cell1||''params''|cell2||''params''|cell3 which will result in cell1 cell2 cell3 Headers Functions the same way as TD, except "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though. Example: !params|cell1 A tag is created by |+ Caption which generates the HTML "Caption". You can also use parameters: |+ params|Caption which will generate "Caption". Square monitors To format for a square monitor or window, use a tape measure. Determine the height of your rectangular screen. Using that figure measure under the screen to determine the width your monitor’s screen would be if it were square. Mark that location using ink or tape under the screen. Drag the side of your browser’s window to that location so the window is square based on accurate measurements. Square monitors and reading windows are not able to contain tables and galleries made for rectangular and wide screens. When a table or gallery is wider than the monitor, it makes every line of text wider than the screen as well. The px amounts of the following gallery were determined after measuring the window to make sure it was square: Type this: For this: Vertically oriented column headers Sometimes it is desirable (such as in a table predominantly made of numbers) to rotate text such that it proceeds from top to bottom or bottom to top instead of from left to right or right to left. Currently, browser support for this type of styling as a component of HTML or CSS is sporadic (Internet Explorer is one of the few browsers that supports this in cascading stylesheets, albeit in a non-standard way). An alternate solution that works in most if not all browsers is to use images in place of the text. For instance, the following table uses SVG images instead of text to produce the rotated column headings: Normally, one problem with this approach is that readers are directed to different pages when they click on the images. To eliminate this problem—or to direct readers to a different page—you can place each image within an image map. A column-header can be coded as follows: ! style="width:3em;" | Image:wpvg_vg_project.svg desc none rect 0 0 12 66 xxxx The image will wikilink to article "xxxx". Note the coding spans 3 lines for each "imagemap". By setting the dimensions of the image map to zero ("rect 0 0 0 0" as in the top-left cell in the above table), no navigation will occur when visitors click on an image. If you specify an alternate link and set the image map's dimensions to equal the size of the image, then readers will be directed elsewhere, just as if the image were a normal text link. Note that it might also be a good idea to color the image text blue if you are using the images as links. Also, SVG is the preferred image format in this case because it can be re-scaled to any size without producing artifacts. Wikitable as image gallery :This section is local to Wikipedia (hard-coded here now). A wikitable can be used to display side-by-side images, in the manner of an image gallery (formatted by ""), but with larger images and less vacant area around photos. A simple framed gallery can be formatted using class="wikitable" to generate the minimal thin-lines around images/photos within the table: Note the result below (with thin-lined cells): Another issue about the standard "" tag, in 2007-2008, was that it put 4 images per line, overrunning the right margin of a wiki article displayed in portrait-style width (like 800x600), unless the gallery had only 3 images. However, a wikitable uses typical image-links with sizes, such as "" so 4 images could be displayed on a wikitable line within a 600px width (for 800x600 resolution screens). Another advantage about wikitable images, compared to "" formatting, is the ability to "square" each image when similar heights are needed, so consider putting 2-number image sizes (such as "199x95px"), where the 2nd number limits height: Note the 3 images sized "199x95px" appear identical height, of 95px (4th image purposely smaller). The "95px" forces height, while "199x" fits the various widths (could even be "999x"): Therefore, the use of size "199x95px" (or "999x95px") produces the auto-height-sizing beyond the "" tag, and with the option to set taller thumbnails ("199x105px"), or even to have some images purposely smaller than other images of "95px" height. A very short height ("70px") allows many more images across the table: The above wikitable-coding produces the result below, of 6 columns: Once images have been placed in a wikitable, control of formatting can be adjusted when more images are added. Shifting/centering Images within a wikitable can be shifted by inserting non-breaking spaces (" ") before or after the image-link (" Image:"). However, auto-centering simply requires use of center-tags to be placed around an image-link for centering in a cell (" "). In the example below, note how Col2 uses , but Col3 uses " ": The above coding generates the table below: note the middle garden image is centered (but not the left image), and the right image has 2 spaces before " View...": Also note that the tag "" made a smaller text-size caption. However, fonts also can be sized by percent (style="font-size:87%"), where the actual percent-size as displayed depends on the various sizes allowed for a particular font. |style="font-size:87%" | View from bell tower The column attribute, above, uses "style=" to set the font-size for the caption, following the 2nd vertical-bar "|". A font-size:65% is very small, while style="font-size:87%" is a mid-size font, larger than the tag small. Speed/transfer rates Actual transfer/display speeds depend on individual files. In 2007 to March 2009 some serious flaws existed in the thumbnailing process when combined with the gallery-display, making thumbnails sometimes larger than the originals. For this reason some users explicitly used tables instead of the gallery tag. However, these issues are fixed as of March 2009. :End of Wikipedia section (hard-coded here now). See also *mw:Table *m:Simplified table syntax *m:Wiki markup tables *m:Table background colors *w:en:User:Dcljr/Tables *w:Table (HTML) * *w:Category:Table and column templates *examples: **Chess board **Go board **Monopoly board **Square 8x8 pentomino example *Wikipedia:How to make a table in Wikipedia *Commons:Convert tables and charts to wiki code *Commons:Chart and graph resources *Cleanup template and its category Category:All articles requiring tables References External links *de:Wikipedia:Helferlein/VBA-Macro for EXCEL tableconversion published in German-Wikipediaproject (English instructions included) *HTML tables to wiki converter at cnic.org *csv2wp - converts comma-separated values (CSV) format to pipe syntax. You may use this to import tables from Excel etc. (more information) *HTML tables to wiki converter at uni-bonn.de *HTML tables to wiki converter at diberri.dyndns.org *pywikipediabot (can convert HTML tables to wiki) *HTML-WikiConverter Various versions and languages *Making Wiki Tables with good examples *Wiki and HTML Tables Ready to Use: A selection of tables and their Wiki/HTML code *Table of CSS color names and HEX codes Category:Wikipedia how-to ar:مساعدة:جدول ca:Ajuda:Taula cs:Nápověda:Tabulky de:Hilfe:Tabellen dsb:Pomoc:Tabela es:Ayuda:Tablas eo:Helpo:Vikitabeloj fa:راهنما:جدول‌ها fr:Aide:Les tableaux pour les novices hsb:Pomoc:Tabela id:Bantuan:Tabel it:Aiuto:Tabelle ka:დახმარება:ცხრილის შექმნა ml:സഹായം:പട്ടിക mn:Тусламж:Хүснэгт яаж хийх вэ? nl:Help:Gebruik van tabellen ja:Help:表の作り方 no:Hjelp:Tabeller km:ជំនួយ:តារាង pl:Pomoc:Tabele pt:Ajuda:Guia de edição/Usar tabelas ro:Ajutor:Tabele qu:Yanapa:Tawla sq:Ndihmë:Tabela sk:Pomoc:Tabuľky sr:Помоћ:Табела fi:Ohje:Taulukot th:วิธีใช้:ตาราง vi:Trợ giúp:Tạo bảng uk:Довідка:Таблиці zh:Help:表格